<?php
declare (strict_types=1);

namespace app\common\model\navi;

use app\admin\model\content\agreement\Agreement;
use app\common\model\BaseModel;
use think\facade\Request;

/**
 * 定义底部导航数据模型
 */
class NaviBottom extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'site_navi_bottom';

    /**
     * 定义表主键
     *
     * @var string
     */
    protected $pk = 'id';

    // 获取内容
    public function getContentAttr($value, $data)
    {
        if ($data['pid'] == 0) {
            return '';
        }

        $content = $data['content'];
        // $is_pc   = request()->is_pc;
        //
        // if (!$is_pc) {
            switch ($data['data_type']) {
                case 0:
                    // 富文本编辑器编辑的内容,列表暂不显示
                    $content = Request::domain() . '/content/single/1/' . $data['id'] . "/content";
                    break;
                case 2:
                    // 协议
                    $agree   = app(Agreement::class)->where('id', $data['content'])->field('id,key,mhm_id')->findOrEmpty();
                    $content = Request::domain() . "/content/agreement/" . $agree->getAttr('key') . "/content/" . $agree->mhm_id;
                    break;
                default:
                    // 其他
                    break;
            }
        // }

        return $content;
    }

}
